package com.ygo.feihua.logo;
import android.app.*;
import android.content.*;
import android.os.*;
import android.util.*;
import android.widget.*;
import com.bumptech.glide.*;
import com.msk86.ygoroid.newutils.*;
import com.ygo.feihua.*;
import java.util.*;
import com.baidu.mapapi.*;
import com.ygo.feihua.task.*;
import com.ygo.feihua.console.*;
import com.qnw.CardGroupManagement.*;
import com.xiaomi.mistatistic.sdk.*;
import com.ygo.feihua.Management.*;
//import com.tencent.smtt.sdk.*;

public class OurygoApplication extends Application
{

	private static Context context;

	public static String MI_PUSH_APP_ID="appId";
	public static String MI_PUSH_APP_KEY="appKey";
	
	private static List<Activity> activitys=new ArrayList<Activity>();;
	
	private static int ii=0;

	private String TAG="OURYGOApplication";
	
	@Override
	public void onCreate()
	{
		super.onCreate();
		context=getApplicationContext();
		SdkInitManagement.getDx().initMiStats();
		
		Log.e(TAG,"开始");
		initMessage();
	}

	private void initMessage() {
		
		String processName = getProcessName(OurygoApplication.this);
		if (processName!= null) {
			if(processName.equals("com.ygo.feihua")&&ii==0){
				ii++;
				registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks(){

						@Override
						public void onActivityCreated(Activity p1, Bundle p2)
						{
							activitys.add(p1);
							// TODO: Implement this method
						}

						@Override
						public void onActivityStarted(Activity p1)
						{
							// TODO: Implement this method
						}

						@Override
						public void onActivityResumed(Activity p1)
						{
							// TODO: Implement this method
						}

						@Override
						public void onActivityPaused(Activity p1)
						{
							// TODO: Implement this method
						}

						@Override
						public void onActivityStopped(Activity p1)
						{
							// TODO: Implement this method
						}

						@Override
						public void onActivitySaveInstanceState(Activity p1, Bundle p2)
						{
							// TODO: Implement this method
						}

						@Override
						public void onActivityDestroyed(Activity p1)
						{
							activitys.remove(p1);
							// TODO: Implement this method
						}
					});


				Log.e(TAG,"主进程");
				Utils.setApplication(getApplicationContext());

				com.msk86.ygoroid.exception.CrashHandler crashHandler =  com.msk86.ygoroid.exception.CrashHandler.getInstance();
				crashHandler.init(getApplicationContext());

				//搜集本地tbs内核信息并上报服务器，服务器返回结果决定使用哪个内核。

			/*	QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {

					@Override
					public void onViewInitFinished(boolean arg0) {
						// TODO Auto-generated method stub
						//x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
						Log.e("app", " onViewInitFinished is " + arg0);
					}

					@Override
					public void onCoreInitFinished() {
						// TODO Auto-generated method stub
					}
				};
				//x5内核初始化接口
				QbSdk.initX5Environment(getApplicationContext(),  cb);
*/
			}else if(processName.equals("system")){
				Log.e(TAG,"系统进程");
			}else{
				Log.e(TAG,"其他进程");
			}
		}

		
		
		// TODO: Implement this method
	}
		
	public static Context getContext(){
		return context;
	}
		
	public static void exit(){
		for(Activity ac:activitys){
			ac.finish();
		}
		System.exit(0);
	}
	
	
	private String getProcessName(Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
        if (runningApps == null) {
            return null;
        }
        for (ActivityManager.RunningAppProcessInfo proInfo : runningApps) {
            if (proInfo.pid == android.os.Process.myPid()) {
                if (proInfo.processName != null) {
                    return proInfo.processName;
                }
            }
        }
        return null;
    }
	
}
